use crate::cli::trace::data::trace_data;
use crate::cli::trace::start::trace_start;
use crate::cli::trace::stop::trace_stop;
use clap::Subcommand;

#[derive(Subcommand, Debug, Clone)]
pub enum TraceSubcommand {
    ///获取Trace数据。
    Data {
        ///Trace数据类型(必选);
        ///支持的数据类型可选值为：1. runtime(运行时数据);
        ///                    2. tpl(模板类数据);
        ///                    3. items(支持的Trace项)。
        #[arg(short = 't', long)]
        data_type: String,
        ///Trace数据输出路径(可选);
        ///若未指定，则默认输出路径为当前目录。
        #[arg(short, long)]
        output_path: Option<String>,
        ///待获取的目标机Trace数据存放路径(可选);
        ///若未指定，则默认路径为:/var/trace.bin。
        #[arg(short, long)]
        target_path: Option<String>,
    },
    ///启动数据跟踪。
    Start {
        ///跟踪集(必选);
        ///该参数为整数类型,通过对待跟踪的子项执行【或】操作生成;
        ///可通过指令：dio trace data --type items查看已支持的所有跟踪子项。
        #[arg(short, long)]
        set: i32,
        ///目标机IP(可选);
        ///若未指定，则使用项目操作(下载/运行)时缓存的目标机IP。
        #[arg(short, long)]
        target_ip: Option<String>,
    },
    ///停止数据跟踪。
    Stop {},
}

pub fn trace_run(cmd: TraceSubcommand) {
    match cmd {
        TraceSubcommand::Data {
            data_type,
            output_path,
            target_path,
        } => {
            trace_data(data_type, output_path, target_path);
        }
        TraceSubcommand::Start { set, target_ip } => {
            trace_start(set, target_ip);
        }
        TraceSubcommand::Stop {} => {
            trace_stop();
        }
    }
}
